package com.kede.typehanlder;

import com.kede.ienum.FenxiaoStatusEnum;
import com.kede.ienum.GoodStatusEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/***
 ** @Author:Pr.li
 ** @Description:
 ** @Date: create in 2023/5/15 22:57
 ***/
public class GoodStatusEnumTypeHanlder extends BaseTypeHandler<GoodStatusEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, GoodStatusEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setInt(i,parameter.getEnumIndex());
    }

    @Override
    public GoodStatusEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        int code = rs.getInt(columnName);
        GoodStatusEnum instance = GoodStatusEnum.parse(code);
        return instance;
    }

    @Override
    public GoodStatusEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        int code = rs.getInt(columnIndex);
        GoodStatusEnum instance = GoodStatusEnum.parse(code);
        return instance;
    }

    @Override
    public GoodStatusEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        return null;
    }
}
